****************************************************************************************************************
**																											  **
** This do file is part of the replication material for the following article: 								  **
**  "Voter mobilization in the echo chamber: Broadband internet and the rise of populism in Europe" 	      **
** 		Authors: Max Schaub, Davide Morisi			    													  **
** 		Journal: European Journal of Political Research														  **
**																											  **
** This file replicates the following step of the analysis: 												  **
**																											  **
**		MERGING AND RECODING DATASETS ITALY	   															  	  **
**																											  **
****************************************************************************************************************

*Set working directory
cd "..."


*******************
*MERGING MUNICIPALITY LEVEL DATASETS

*Istat data
use "Replication files\italy_istat.dta", clear
gen mergevar1=istatnew
save "Replication files\italy_istat.dta", replace

*Broadband data
use "Replication files\italy_broadband.dta", clear
gen mergevar1=id_comunenew2
save "Replication files\italy_broadband.dta", replace

*Merging Istat data and broadband data
use "Replication files\italy_istat.dta", clear
merge 1:1 mergevar1 using "Replication files\italy_broadband.dta"
*91 not matched municipalities
*From master: 69 municipalities that don't exist after 2013
*list municip if _merge==1
*From using: 22 municipalities: mostly new municip created after 2013 by merging old municipalities
*New mergevar, including the 22 unmatched municip from using
gen mergevar2=istatnew
replace mergevar2 = id_comunenew2 if istatnew==.
save "Replication files\italy_merged.dta", replace

*Topography data
use "Replication files\italy_topography.dta", clear
gen mergevar2 = istat_code_11
save "Replication files\italy_topography.dta", replace

*Merging with topography data
use "Replication files\italy_merged.dta", clear
drop _merge
merge 1:1 mergevar2 using "Replication files\italy_topography.dta"
drop _merge
save "Replication files\italy_merged.dta", replace


***********************
*Merging with ITANES panel, 2011-2013 CATI (individual leve)

*Original data: 2013 inter-electoral ITANES panel, Belluci and Maraffi, 2014
*Downloaded from http://www.itanes.org/dati/ on 22 October 2019 (publicly available)

use "Data\Data - Italy\ITANES_PANEL_2011_13_CATI_Ver_04_2018\ITANES_PANEL_2011_13_CATI_Ver_04_2018", clear

*Changing istat code for municipalities that have old code in Itanes dataset
gen mergevar2=Cod_comune_107province 
replace mergevar2=108004 if COMUNE=="ARCORE"
replace mergevar2=110002 if COMUNE=="BARLETTA"
replace mergevar2=108006 if COMUNE=="BELLUSCO"
replace mergevar2=108007 if COMUNE=="BERNAREGGIO"
replace mergevar2=108009 if COMUNE=="BIASSONO"
replace mergevar2=108012 if COMUNE=="BRUGHERIO"
replace mergevar2=108018 if COMUNE=="CERIANO LAGHETTO"
replace mergevar2=108019 if COMUNE=="CESANO MADERNO"
replace mergevar2=108020 if COMUNE=="COGLIATE"
replace mergevar2=109006 if COMUNE=="FERMO"
replace mergevar2=108026 if COMUNE=="LESMO"
replace mergevar2=109012 if COMUNE=="MONSAMPIETRO MORICO"
replace mergevar2=109024 if COMUNE=="MONTE URANO"
replace mergevar2=108035 if COMUNE=="NOVA MILANESE"
replace mergevar2=109034 if COMUNE=="PORTO SANT'ELPIDIO"
replace mergevar2=108039 if COMUNE=="SEREGNO"
replace mergevar2=108041 if COMUNE=="SOVICO"
replace mergevar2=110009 if COMUNE=="TRANI"
replace mergevar2=110010 if COMUNE=="TRINITAPOLI"
replace mergevar2=108047 if COMUNE=="VEDUGGIO CON COLZANO"
replace mergevar2=108049 if COMUNE=="VILLASANTA"

*Additional changes
replace mergevar2=108001 if COMUNE=="AGRATE BRIANZA"
replace mergevar2=108003 if COMUNE=="ALBIATE"
replace mergevar2=109001 if COMUNE=="ALTIDONA"
replace mergevar2=109002 if COMUNE=="AMANDOLA"
replace mergevar2=110001 if COMUNE=="ANDRIA"
replace mergevar2=108005 if COMUNE=="BARLASSINA"
replace mergevar2=108008 if COMUNE=="BESANA IN BRIANZA"
replace mergevar2=110003 if COMUNE=="BISCEGLIE"
replace mergevar2=108010 if COMUNE=="BOVISIO MASCIAGO"
replace mergevar2=110004 if COMUNE=="CANOSA DI PUGLIA"
replace mergevar2=108015 if COMUNE=="CARATE BRIANZA"
replace mergevar2=108017 if COMUNE=="CAVENAGO DI BRIANZA"
replace mergevar2=108021 if COMUNE=="CONCOREZZO"
replace mergevar2=108023 if COMUNE=="DESIO"
replace mergevar2=109005 if COMUNE=="FALERONE"
replace mergevar2=108024 if COMUNE=="GIUSSANO"
replace mergevar2=13249 if COMUNE=="GRAVEDONA"
replace mergevar2=108054 if COMUNE=="LENTATE SUL SEVESO"
replace mergevar2=108027 if COMUNE=="LIMBIATE"
replace mergevar2=108028 if COMUNE=="LISSONE"
replace mergevar2=110005 if COMUNE=="MARGHERITA DI SAVOIA"
replace mergevar2=108030 if COMUNE=="MEDA"
replace mergevar2=108032 if COMUNE=="MISINTO"
replace mergevar2=109014 if COMUNE=="MONTEFALCONE APPENNINO"
replace mergevar2=109015 if COMUNE=="MONTEFORTINO"
replace mergevar2=108033 if COMUNE=="MONZA"
replace mergevar2=108034 if COMUNE=="MUGGIO'"
replace mergevar2=109031 if COMUNE=="PETRITOLI"
replace mergevar2=109033 if COMUNE=="PORTO SAN GIORGIO"
replace mergevar2=109037 if COMUNE=="SANT'ELPIDIO A MARE"
replace mergevar2=108040 if COMUNE=="SEVESO"
replace mergevar2=110008 if COMUNE=="SPINAZZOLA"
replace mergevar2=108043 if COMUNE=="TRIUGGIO"
replace mergevar2=108044 if COMUNE=="USMATE VELATE"
replace mergevar2=108045 if COMUNE=="VAREDO"
replace mergevar2=108046 if COMUNE=="VEDANO AL LAMBRO"
replace mergevar2=108048 if COMUNE=="VERANO BRIANZA"
replace mergevar2=108050 if COMUNE=="VIMERCATE"

*Save
save "Replication files\italy_itanes_panel_recoded.dta", replace

merge m:1 mergevar2 using "Replication files\italy_merged.dta"
*municipalities from masters are all matched 
*non-matched municipalities = municipalities not included in Itanes panel
drop if _merge==2

save "Replication files\italy_itanes_panel_recoded.dta", replace








